<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
		<style>
			.layui-laypage-limits {
				display: none !important;
			}
		</style>
	</head>

	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend style="text-align: center">FNST-在线笔试系统</legend>
		</fieldset>
		<div style="padding: 20px; background-color: #F2F2F2;">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-header">笔试管理</div>

						<div class="layui-card-body">
							<div class="layui-form-item">
								<div>
									<button class="layui-btn " id="addBs"><a style="color:white"  href="examPublish.html" target="iframe"> <i class="layui-icon">&#xe608;</i>发布笔试</a></button>
								</div>
							</div>
							<table id="demo" lay-filter="test"></table>
						</div>

					</div>
				</div>
			</div>
		</div>
		<input  style='opacity: 0;position: absolute;' type="text" id="hiddenUrl" />
		<script type="text/html" id="barDemo">
			<a class="layui-btn  layui-btn-xs" lay-event="edit">复制链接</a>
			<a class="layui-btn  layui-btn-xs" lay-event="view">查看答题</a>
			<a class="layui-btn  layui-btn-xs" lay-event="playback">答题回放</a>
		</script>

		<script src="../../layui/layui.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script>
			layui.config({
				base: './../dist/'
			}).extend({
				notice: 'notice'
			});
			function formatDate(now) {
				var year = now.getFullYear();
				var month = now.getMonth() + 1;
				var date = now.getDate();
				var hour = now.getHours();
				var minute = now.getMinutes();
				var second = now.getSeconds();
				return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
			}
			layui.use(['notice', 'table', 'jquery', 'layer'], function() {
				var notice = layui.notice; // 允许别名 toastr
				var table = layui.table;
				//第一个实例
				table.render({
					elem: '#demo',
					height: 312,
					url: host() + "/getUserListAfterPublishWrittenTest?token=" + localStorage.token,
					page: true,
					limit: 5,
					limits: [5, 10, 15, 20, 25, 30],
					cols: [
						[ //表头
							{
								field: 'id',
								title: '笔试者ID'
							},
							{
								field: 'username',
								title: '笔试者姓名'
							}, {
								field: 'startTime',
								title: '笔试开始时间',
								templet: function(d) {
									if(d.startTime == null) return "";
									else {
										var d = new Date(d.startTime);
										return formatDate(d);
									}
								},
								sort: true
							}, {
								field: 'endTime',
								title: '笔试结束时间',
								templet: function(d) {
									if(d.endTime == null) return "";
									else {
										var d = new Date(d.endTime);
										return formatDate(d);
									}
								},
								sort: true
							},
							{
								field: 'bszt',
								title: '笔试状态',
								templet: function(d) {
									if(d.startTime == null)
										return "笔试未开始";
									else if(d.startTime != null && d.endTime == null)
										return "笔试进行中";
									else if(d.startTime != null && d.endTime != null)
										return "笔试已结束";
								}
							}, {
								fixed: 'right',
								title: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;操作',
								toolbar: '#barDemo',
								width: 260
							}

						]
					]
				});

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					if(obj.event === 'edit') {
						console.log(obj.data.testUrl);　　
						$("#hiddenUrl").val(obj.data.testUrl);
						var input = document.querySelector('#hiddenUrl');
						input.select();
						
						if(document.execCommand('copy')) {
							document.execCommand('copy');
							notice.success('复制成功');
						}

					}
					if(obj.event === 'view') {
						var data = obj.data;
						if(data.startTime == null) {
							notice.warning("当前笔试未开始，不能查看");
							return;
						}
						if(data.endTime != null) {
							notice.warning("当前笔试已结束，不能查看");
							return;
						}
						localStorage.setItem("bsusername", data.username);
						window.open("examView.html?userid=" + data.id);
					}
					if(obj.event === 'playback') {
						var data = obj.data;
						if(data.startTime == null) {
							notice.warning("当前笔试未开始，不能回放");
							return;
						}
						if(data.endTime == null) {
							notice.warning("当前笔试未结束，不能回放");
							return;
						}
						localStorage.setItem("bsusername", data.username);
						window.open("examPlayback.html?userid=" + data.id);
					}
				});
			});
		</script>
	</body>

</html>